home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmigaPlus / Tools / Development / AmigaTalk / general / ValueHolder.st < prev    next >
Encoding:
Text File  |  2004-01-31  |  1.9 KB  |  69 lines

  1. " ---------------------------------------------------------------------
  2.   ValueHolder is a very simple Model, no more than a value 
  3.   holder with updates.
  4.  
  5.   Instance variables:
  6.     value  <Object> the current value
  7.  
  8.  
  9.   Object Reference:
  10.   A ValueHolder is the simplest value model. It merely holds a value, 
  11.   and notifies the dependents of that value whenever it is changed. 
  12.   A ValueHolder is widely used to enfold the strings, numbers and 
  13.   other data objects that are displayed in widgets.  For this reason, 
  14.   every object has been made capable of enfolding itself in a ValueHolder 
  15.   when it receives an #asValue message.  ValueHolder also provides both 
  16.   general and specialized creation messages for enfolding a given value.
  17.   ValueHolder has several specialized subclasses.  BufferedValueHolder 
  18.   is the most general and reusable subclass -- it holds a working 
  19.   copy of the value as well as a confirmed copy, for situations in 
  20.   which the application must be prepared to undo a change in the 
  21.   value until a confirmation step has been taken. 
  22.  ----------------------------------------------------------------------
  23. "
  24.  
  25. Class ValueHolder :ValueModel ! value !
  26. [
  27.    dependents
  28.  
  29.      ^ super dependents
  30. |     
  31.    newBoolean
  32.      " Answer a new instance, initialized to false. "
  33.  
  34.      ^self with: false
  35. |
  36.    newFraction
  37.      " Answer a new instance, initialized to 0.0. "
  38.  
  39.      ^ self with: 0.0
  40. |
  41.    newString
  42.      " Answer a new instance, initialized to an empty string. "
  43.  
  44.      ^ self with: (String new: 0)
  45. |
  46.    with: initialValue
  47.      " Answer a new instance, initialized to the given value. "
  48.  
  49.      ^ self new setValue: initialValue
  50. |
  51.    setValue: aValue
  52.      " Just initialize the value without notifying
  53.      * dependents of a change. 
  54.      "
  55.  
  56.      value <- aValue
  57.  
  58. |
  59.    value
  60.      ^ value
  61. |
  62.    printOn: aStream 
  63.      "Let what is printed reflect the value of the receiver."
  64.  
  65.      super printOn: aStream.
  66.  
  67.      aStream nextPutAll: ' on: '; print: self value
  68. ]
  69.